package com.syz.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.syz.mall.mapper.UserMapper;
import com.syz.mall.pojo.Product;
import com.syz.mall.pojo.User;
import com.syz.mall.pojo.query.UserQuery;
import com.syz.mall.service.IUserService;
import com.syz.mall.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String username, String password) {
        return userMapper.managerLogin(username, password);
    }

    @Override
    public LayUITableResult selectByPage(UserQuery userQuery) {
        PageHelper.startPage(userQuery.getPage(), userQuery.getLimit());
        List<User> list = userMapper.selectAll(userQuery);
        PageInfo pageInfo = new PageInfo(list);
        long totalCount = pageInfo.getTotal();
        return LayUITableResult.ok((int)totalCount, list);
    }

    @Override
    public Boolean updateSelective(User user) {
        int count=userMapper.updateByPrimaryKeySelective(user);
        return count==1;
    }


}
